package cn.chengpengper.shortlink.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.scheduling.annotation.EnableAsync;
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;

import java.util.concurrent.ThreadPoolExecutor;

/**
 * @author huchengpeng
 * @version v1.0.0
 * @date 2023/8/20 21:18
 * @description 线程池配置
 */
@EnableAsync
@Configuration
public class ThreadPoolTaskConfig {

    @Bean("smsTaskExecutor")
    public ThreadPoolTaskExecutor smsTaskExecutor() {
        ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor();
        executor.setCorePoolSize(8);
        executor.setMaxPoolSize(64);
        executor.setQueueCapacity(128);
        executor.setKeepAliveSeconds(30);
        executor.setThreadNamePrefix("Async-sms-thread-");
        executor.setRejectedExecutionHandler(new ThreadPoolExecutor.AbortPolicy());
        executor.initialize();
        return executor;
    }
}
